using System;
using Gtk;
using MySql.Data.MySqlClient;
using PConexionMySql;


public partial class MainWindow : Gtk.Window
{
	public MySqlConnection Connection;
	public MySqlCommand Command;
	public MySqlDataReader DataReader;
	
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		consultarAccion.Activated += delegate 
		{
			Connection = MySqlConnetionHelper.Connection();
			Command = Connection.CreateCommand();
			Command.CommandText = "SELECT * FROM articulo;";
			MySqlConnetionHelper.OpenConexion();
			DataReader = Command.ExecuteReader();
			for(int i=0;i<DataReader.FieldCount;i++)
			{
				treeView.AppendColumn(DataReader.GetName(i), new CellRendererText(), "text", i);
			}
			Type[] types = new Type[DataReader.FieldCount];
			for(int i=0;i<types.Length;i++)
			{
				types[i]=typeof(string);
			}
			ListStore listStore = new ListStore(types);
			treeView.Model = listStore;
			object[] values = new object[DataReader.FieldCount];
			string[] strings = new string[values.Length];
			while(DataReader.Read())
			{
				DataReader.GetValues(values);
				for(int i=0;i<values.Length; i++)
				{
					strings[i]=values[i].ToString();
				}
				listStore.AppendValues(strings);
			}
			DataReader.Close();
			
		};
	}
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		MySqlConnetionHelper.CloseConexion();
		Application.Quit ();
		a.RetVal = true;
	}
}

